package com.example.administrator.dagger2demo.di;

import android.util.Log;

import com.example.administrator.dagger2demo.http.RestApi;

import javax.inject.Singleton;

import dagger.Module;
import dagger.Provides;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Administrator on 2016/4/12.
 */
@Module
public class ApiModule {


    @Provides
    @Singleton
    protected RestApi provideRestApi(Retrofit retrofit) {
        Log.i("TAG",retrofit==null?"进入了...provideRestApi-is null":"进入了...provideRestApi-not null");
        return retrofit.create(RestApi.class);
    }

    @Provides
    @Singleton
    protected  Retrofit provideRetrofit() {
        Log.i("TAG","进入了...provideRetrofit");



        return new Retrofit.Builder()
                .client(new OkHttpClient())
                .baseUrl(RestApi.BASE_URL)
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) // 添加Rx适配器
                .addConverterFactory(GsonConverterFactory.create()) // 添加GSon转换器
                .build();
    }
}
